package cn.com.blackboard.SISIntergrationBiz.controller;

import java.io.IOException;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cm.com.blackboard.DataModule4B2.customizeConfigUtils.CreditMapPropertiesUtil;
import cn.com.blackboard.DataModule4B2.BBDataUtils.LocaleUtil;
  
@Controller
@RequestMapping("/creditresult")
public class CreditMapSetController {  
	
	private static final Logger logger = LoggerFactory.getLogger(CreditMapSetController.class);
    
    @RequestMapping("/load")  
    public String getProps(ModelMap modelMap) throws IOException{	
    	logger.info("into load controller");
    	
		modelMap.addAttribute("creditMapSet", CreditMapPropertiesUtil.getMap().entrySet());	
		Locale locale = LocaleUtil.getLocale();
		modelMap.addAttribute("locale", locale.toString());
		return "/config/configCreditMap"; 
    }
    
    @RequestMapping(value = "set", method = {RequestMethod.POST },produces={"text/html;charset=UTF-8;","application/json;"})
    @ResponseBody
    public String setProps(@RequestBody List<Map<String,String>> lstMap) throws IOException{	
    	logger.info("into set controller");
		for(Map<String,String> map:lstMap){
			CreditMapPropertiesUtil.updateProperties(map.get("key"), map.get("value"));
			logger.info("finished updating credit Map key pair key:"+map.get("key")+"------value:"+map.get("value"));
		}	
		return "/config/configCreditMap"; 
    }

}  
